package com.example.lawyer.databind.activity;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.example.lawyer.BR;
import com.example.lawyer.R;
import com.example.lawyer.adapter.CurrentAdapters;
import com.example.lawyer.databind.assembly.GeneralTopTitleData;
import com.example.lawyer.databind.itemview.ItemBiaoQingData;

import java.util.List;

public class ActivitryChatDataBindModel {
    //顶部标题
    public ObservableField<GeneralTopTitleData>  GeneralTop = new ObservableField<>();

    //输入内容
    public ObservableField<String> edittext = new ObservableField<>();
    //表情列表
    public ObservableField<List<ItemBiaoQingData>> biaoqinglist = new ObservableField<>();
    //表情控制
    public ObservableField<Boolean> isbiaoqingshow = new ObservableField<>();


    //展开表情
    public void onClickBiaoQing(View view)
    {
        Context context = view.getContext();
        if(!this.isbiaoqingshow.get()) {

            int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
            int heightPixels = context.getResources().getDisplayMetrics().heightPixels;
            System.out.println(widthPixels);
            System.out.println(widthPixels);

            this.isbiaoqingshow.set(true);

            View parent = (View) view.getParent();
            View parents = (View) parent.getParent();
            View viewById = parents.findViewById(R.id.optgroud);

            ViewGroup.LayoutParams layoutParams = viewById.getLayoutParams();
            layoutParams.height = heightPixels / 3;

            viewById.setLayoutParams(layoutParams);
        }else {

            View parent = (View) view.getParent();
            View parents = (View) parent.getParent();
            View viewById = parents.findViewById(R.id.optgroud);

            ViewGroup.LayoutParams layoutParams = viewById.getLayoutParams();
            layoutParams.height = 0;
            viewById.setLayoutParams(layoutParams);
            this.isbiaoqingshow.set(false);

        }

    }

    //初始化表情列表
    @BindingAdapter("setAdapter")
    public static void InitBiaoQing(View view,List<ItemBiaoQingData> data)
    {


        CurrentAdapters adapters = new CurrentAdapters(data,R.layout.item_biaoqing_view, BR.itembiaoqingdata);
        GridView gridView = (GridView) view;
        gridView.setAdapter(adapters);
    }


}
